function [out]=wrapp_back(window,img_size,center)
%inverts the wrapp_around function
%
% author: Sebastian Schmelcher        Version: 2012-06-19

out=zeros(img_size);

ys=img_size(1);
xs=img_size(2);

yc=center(1);
xc=center(2);

if(yc<1 || yc>ys || xc<1 || xc>xs)
    error('wrapp_back: Center not inside img_size!');
end

window_size=size(window);
yw=window_size(1);
xw=window_size(2);

% Adding the four axial-alined rectangles around the center with regards to image boundaries
out(max(yc-yw,1):yc-1,max(xc-xw,1):xc-1)=window(max(1,yw-yc+2):yw,max(1,xw-xc+2):xw); %upper left
out(max(yc-yw,1):yc-1,xc:min(xc+xw-1,xs))=window(max(1,yw-yc+2):yw,1:min(xw,xw+xs-xc-xw+1)); %upper right
out(yc:min(yc+yw-1,ys),max(xc-xw,1):xc-1)=window(1:min(yw,yw+ys-yc-yw+1),max(1,xw-xc+2):xw); %lower left
out(yc:min(yc+yw-1,ys),xc:min(xc+xw-1,xs))=window(1:min(yw,yw+ys-yc-yw+1),1:min(xw,xw+xs-xc-xw+1)); %lower right